<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>驴妈妈流立方</title>
		<meta name="description" content="overview &amp; stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
		<!-- bootstrap & fontawesome -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/bootstrap.min.css" />
		<link rel="stylesheet" href="${rc.contextPath}/assets/font-awesome/4.5.0/css/font-awesome.min.css" />
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/daterangepicker.min.css" />
		<!-- text fonts -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/fonts.googleapis.com.css" />
		<!-- ace styles -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/ace-skins.min.css" />
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/jquery.gritter.min.css" />
		<!-- ace settings handler -->
		<script src="${rc.contextPath}/assets/js/ace-extra.min.js"></script>
	</head>

	<body class="skin-2" style="background-color: #FFF;">
		      <div class="page-content">
    <div class="page-header">
        <h1>
                          新建规则
        </h1>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <form id="ruleformForm" class="form-horizontal" role="form" action="${rc.contextPath}/webStatistics/saveRule" method="POST">
                    <input type="hidden" id="rules" name="rules" value="">
                <div class="form-group"><label class="col-sm-3 control-label no-padding-right" for="form-field-1">
					<strong class="text-danger"><front color="red">*</front></strong>规则类型 ： </label>
                    <div class="col-sm-8">
                        <input type="text" id="name" name="name" placeholder="请输入规则类型" value="" class="col-xs-10 col-sm-5">
                    </div>
                </div>
                        <div class="space-4"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">
							       <button id="newrulesCopy" type="button" class="btn btn-primary btn-sm btn-round">添加配置规则</button>
							</label>
							<div class="col-sm-9" id="rulesCopys">
									<div id="${rule_index + 1}">
										<br>
										<div class="col-sm-1">
							            <button type="button" onclick="deleterulesCopy(this);" class="btn btn-danger btn-sm btn-round">删除配置规则</button>
							            </div>
										<label class="col-sm-1 control-label no-padding-right" for="form-field-1">
										<strong class="text-danger">*</strong>URL配置： </label>
										<input type="text" id="linkUrl${rule_index + 1}" name="linkUrl${rule_index + 1}" maxlength="80" placeholder="请填写 URL配置" value="" class="col-xs-8 col-sm-4">
									    <!-- <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
										<strong class="text-danger">*</strong>查询条件： </label>
										<input type="text" id="conditionName${rule_index + 1}" name="conditionName${rule_index + 1}" maxlength="10" placeholder="or 或者 and" value="" class="col-xs-2 col-sm-1"> -->
										<div  class="col-sm-12">
										<hr class="col-sm-12">
										</div>
									</div>
							</div>
						</div>

                <div class="clearfix form-actions">
                    <div class="col-md-offset-4 col-md-8">
                        <button id="submitBtn" class="btn btn-info" type="button">
                            <i class="ace-icon fa fa-check bigger-110"></i>
                                                                  保存
                        </button>
                        <button class="btn btn-info" type="button" onclick="skip('${rc.contextPath}/webStatistics/firstScreenTimeCount')" style="margin-left:10px;">
							<i class="ace-icon fa fa-undo bigger-110"></i>
						   取消
						</button>
                    </div>
                    
                </div>
                <div class="page-header">
			        <h1>
			                           说明：<font class="page-header" size="3">第一条规则用于精确匹配, 其次的用于匹配条件,如SQL相当于 url = "m.lvmama.com/hotel/dj/" OR url LIKE "%v-*%" OR url LIKE "%/dj/comment-*%"</font>
			        </h1>
			    </div>
            </form>
        </div><!-- /.col -->
    </div><!-- /.row -->
</div>
		<script src="${rc.contextPath}/assets/js/jquery-2.1.4.min.js"></script>
		<script type="text/javascript">
			if('ontouchstart' in document.documentElement) document.write("<script src='${rc.contextPath}/assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script src="${rc.contextPath}/assets/js/bootstrap.min.js"></script>

		<!-- page specific plugin scripts -->
		<script src="${rc.contextPath}/assets/js/jquery-ui.min.js"></script>
		<script src="${rc.contextPath}/assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="${rc.contextPath}/assets/js/jquery.gritter.min.js"></script>

		<!-- ace scripts -->
		<script src="${rc.contextPath}/assets/js/ace-elements.min.js"></script>
		<script src="${rc.contextPath}/assets/js/ace.min.js"></script>
		<!-- user scripts -->
		<script src="${rc.contextPath}/assets/js/user/base.js"></script>
		<script type="text/javascript">
			
			var deleterulesCopy=function(obj){
				$(obj).parent().parent().remove();
			}
		
			jQuery(function($) {
				var i=$("#rulesCopys").children().length;
				$('#newrulesCopy').on('click',function() {
					i++;
					$('#rulesCopys').append('<div id="'+i+'">'+
							'<br>'+
							'<div class="col-sm-1">'+
							'<button type="button" onclick="deleterulesCopy(this);" class="btn btn-danger btn-sm btn-round">删除配置规则</button>'+
						    '</div>'+
							'<label class="col-sm-1 control-label no-padding-right" for="form-field-1">'+
							'<strong class="text-danger">*</strong>URL配置： </label>'+
							'<input type="text" id="linkUrl'+i+'" name="linkUrl'+i+'" maxlength="80" placeholder="请填写 URL配置" value="" class="col-xs-8 col-sm-4">'+
						    '<label class="col-sm-1 control-label no-padding-right" for="form-field-1">'+
							'<strong class="text-danger">*</strong>查询条件： </label>'+
							'<input type="text" id="conditionName'+i+'" name="conditionName'+i+'" maxlength="10" placeholder="or 或者 and" value="" class="col-xs-2 col-sm-1">'+ 
							'<div  class="col-sm-12">'+
							'<hr class="col-sm-12">'+
							'</div>'+
						'</div>'
						);
				});
			});
			
			
			$('#deleterulesCopy').on('click',function(){
				$(this).parent().parent().remove();
			});
			
		
			$('#submitBtn').on('click', function(){
				var z=0;
				var rules=[];
				var rulesCopys={};
				var isHave=false;
				$("#rulesCopys").children().each(function(){
					isHave=true;
					var id=$(this).attr("id");
					var obj={};
				    var linkUrl=$(this).find("#linkUrl"+id).val();
					obj.linkUrl=linkUrl;
					var conditionName=$(this).find("#conditionName"+id).val();
					obj.conditionName=conditionName; 
					
					obj.ruleOrder=z;
					rules[z]=obj;
					z++;
				});
				rulesCopys.rules=rules;
				
				var name = $("#name").val();
				
				//数据合法性校验
				 if(!name) {
					showMsg("请添加规则类型!");
				} else { 
					$("#rules").attr("value",JSON.stringify(rulesCopys));
					showMsg("添加成功!");
					$("#ruleformForm").submit();
			    }
			});
				
		</script>
	</body>
</html>